﻿/******************************************************************
** 文 件 名: Bu_AuditTable_FGW_DAL.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2013/3/1 17:19:34
** 描    述: 实现公共部分的数据访问封装，提供资金支付汇总表-发改委返回的数据访问类
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.DataAccess
{
	/// <summary>
    /// Bu_AuditTable_FGW数据访问类
    /// </summary>
	public partial class Bu_AuditTable_FGW_DAL : BaseDataAccess<Bu_AuditTable_FGW>
    {		
		/// <summary>
        /// 构造函数，使用指定的连接字符串
        /// </summary>
        /// <param name="connectionStringName">连接字符串名称</param>
        public Bu_AuditTable_FGW_DAL(string connectionStringName)
            : base(connectionStringName)
        {

        }
        /// <summary>
        /// 得到发改委返回的资金支付汇总表
        /// </summary>
        /// <param name="batchNo"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetFGWList(int batchNo, int pageSize, int currentPageIndex, out int recordCount)
        {
            DbCommand command = GetStoredProcCommand("Proc_GetGFWList");
            DbParameter pBatchNo = CreateParameter("batchNo");
            pBatchNo.DbType = DbType.Int32;
            pBatchNo.Value = batchNo;
            DbParameter pPageSize = CreateParameter("pageSize");
            pPageSize.DbType = DbType.Int32;
            pPageSize.Value = pageSize;
            DbParameter pCurrentPageIndex = CreateParameter("currentPageIndex");
            pCurrentPageIndex.DbType = DbType.Int32;
            pCurrentPageIndex.Value = currentPageIndex;
            DbParameter pRecordCount = CreateParameter("recordCount");
            pRecordCount.DbType = DbType.Int32;
            pRecordCount.Direction = ParameterDirection.Output;
            command.Parameters.Add(pBatchNo);
            command.Parameters.Add(pPageSize);
            command.Parameters.Add(pCurrentPageIndex);
            command.Parameters.Add(pRecordCount);
            DataTable dt = ExecuteDataTable(command);
            recordCount = Convert.ToInt32(pRecordCount.Value);
            return dt;
        }

        /// <summary>
        /// 得到可选择的作业表
        /// </summary>
        /// <param name="batchNo"></param>
        /// <param name="rptDate"></param>
        /// <returns></returns>
        public DataTable GetFWGSelectAT(int batchNo)
        {
            DbCommand command = GetStoredProcCommand("GetBatchSummary");
            DbParameter pBatchNo = CreateParameter("batchNo");
            pBatchNo.DbType = DbType.Int32;
            pBatchNo.Value = batchNo;
            //DbParameter pRptDate = CreateParameter("printDate");
            //pRptDate.DbType = DbType.DateTime;
            //pRptDate.Value = rptDate;
            command.Parameters.Add(pBatchNo);
            //command.Parameters.Add(pRptDate);
            DataTable dt = ExecuteDataTable(command);
            return dt;
        }

        /// <summary>
        /// 得到批次已经选择的作业表
        /// </summary>
        /// <param name="batchNo"></param>
        /// <returns></returns>
        public DataTable GetFGWSelectedAT(int batchNo)
        { 
            DbParameter param = CreateParameter("BatchNo");
            param.DbType = DbType.Int32;
            param.Value = batchNo;
            string sql = string.Format(@"Select A.ATID
                From Bu_AuditTable_FGWDetail A
                Inner Join Bu_AuditTable_FGW B
                On A.FGWID=B.ID
                Where B.BatchNo={0}", param.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(param);
            return ExecuteDataTable(command);
        }

        public void SetBatchIsEnd(bool b,string batchId,DbTransaction transaction)
        {
            DbParameter pIsEnd = CreateParameter("IsEnd");
            pIsEnd.DbType = DbType.Boolean;
            pIsEnd.Value = b;
            DbParameter pBatchID=CreateParameter("BatchID");
            pBatchID.DbType = DbType.String;
            pBatchID.Value=batchId;
            string sql = string.Format(@"Update Bu_AuditTable_FGW Set IsEnd={0} Where BatchID={1}", pIsEnd.ParameterName, pBatchID.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(pIsEnd);
            command.Parameters.Add(pBatchID);
            ExecuteNonQuery(command, transaction);
        }

        /// <summary>
        /// 是否存在某个汇总表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool IsExists(string id)
        {
            DbParameter pID = CreateParameter("batchNo");
            pID.DbType = DbType.String;
            pID.Value = id;
            string sql = string.Format(@"Select Count(ID) From Bu_AuditTable_FGW Where ID={0}", pID.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(pID);
            int obj = Convert.ToInt32(ExecuteScalar(command));
            return obj == 1;
        }
    }
}
